package com.sitech.portal.server.action;

import java.net.URLDecoder;
import java.util.List;

import com.sitech.ibnms.core.JGridBaseAction;
import com.sitech.ibnms.util.AppException;
import com.sitech.portal.server.form.ShortcutForm;
import com.sitech.portal.server.form.ShortcutTypeForm;
import com.sitech.portal.server.service.IShortcutService;

public class ShortcutAction extends JGridBaseAction{
	
	IShortcutService shortcutService;
	ShortcutForm shortcutForm;
	ShortcutTypeForm shortcutTypeForm;
	List<ShortcutForm> shortcutList;
	List<ShortcutTypeForm> shortcutTypeList;
	boolean flag = true;
	
	public String save() throws Exception{
		try {
			String name = URLDecoder.decode(shortcutForm.getShortcut_name(), "UTF-8");
			shortcutForm.setShortcut_name(name);
			shortcutService.save(shortcutForm);
		} catch (Exception e) {
			flag = false;
			throw new AppException("插入快捷菜单时发生异常",e);
		}
		return SUCCESS;
	}
	
	public String delete() throws Exception{
		try {
			shortcutService.delete(shortcutForm);
		} catch (Exception e) {
			flag = false;
			throw new AppException("插入快捷菜单时发生异常",e);
		}
		return SUCCESS;
	}
	
	public String saveType() throws Exception{
		try {
			if(shortcutTypeForm.getLogin_id()==null||shortcutTypeForm.getLogin_id().equals(""))
				shortcutTypeForm.setLogin_id(this.getCurrentUser().LOGIN_ID);
			
			String name = URLDecoder.decode(shortcutTypeForm.getType_name(), "UTF-8");
			shortcutTypeForm.setType_name(name);
			shortcutService.saveType(shortcutTypeForm);
		} catch (Exception e) {
			flag = false;
			throw new AppException("插入快捷菜单时发生异常",e);
		}
		return SUCCESS;
	}
	
	public String deleteType() throws Exception{
		try {
			shortcutService.deleteType(shortcutTypeForm);
		} catch (Exception e) {
			flag = false;
			throw new AppException("插入快捷菜单时发生异常",e);
		}
		return SUCCESS;
	}
	
	public String queryShortcut()throws Exception{
		try {
			shortcutList = shortcutService.query(this.getCurrentUser().getLOGIN_ID());
		} catch (Exception e) {
			throw new AppException("插入快捷菜单时发生异常",e);
		}
		return SUCCESS;
	}
	
	public String queryShortcutType()throws Exception{
		try {
			shortcutTypeList  = shortcutService.queryType(this.getCurrentUser().getLOGIN_ID());
		} catch (Exception e) {
			throw new AppException("插入快捷菜单时发生异常",e);
		}
		return SUCCESS;
	}
	
	public String loadShortcutManange(){
		return SUCCESS;
	}

	public IShortcutService getShortcutService() {
		return shortcutService;
	}

	public void setShortcutService(IShortcutService shortcutService) {
		this.shortcutService = shortcutService;
	}

	public ShortcutForm getShortcutForm() {
		return shortcutForm;
	}

	public void setShortcutForm(ShortcutForm shortcutForm) {
		this.shortcutForm = shortcutForm;
	}

	public ShortcutTypeForm getShortcutTypeForm() {
		return shortcutTypeForm;
	}

	public void setShortcutTypeForm(ShortcutTypeForm shortcutTypeForm) {
		this.shortcutTypeForm = shortcutTypeForm;
	}

	public List<ShortcutForm> getShortcutList() {
		return shortcutList;
	}

	public void setShortcutList(List<ShortcutForm> shortcutList) {
		this.shortcutList = shortcutList;
	}

	public List<ShortcutTypeForm> getShortcutTypeList() {
		return shortcutTypeList;
	}

	public void setShortcutTypeList(List<ShortcutTypeForm> shortcutTypeList) {
		this.shortcutTypeList = shortcutTypeList;
	}
	
}
